from PIL import Image

img = Image.open('/Users/cai/PycharmProjects/PythonProject/assert/icon_sxw.png')

background = Image.new("RGBA", img.size, (255, 255, 255))
background.paste(img, mask=img.split()[3])

datas = img.getdata()
newData = list()

for item in datas:
    if item[0] == 255 and item[1] == 255 and item[2] == 255:
        newData.append((255, 255, 255, 0))
    else:
        newData.append((200, 200, 200, 255))

background.putdata(newData)

# 完成了白色到透明的转换

background.show()

background.save('/Users/cai/PycharmProjects/PythonProject/assert/icon_sxw_trans.png')